<?php if (!$sf_request->isMethod('POST')): ?>
    <?php echo '<div id="health-advice-form-holder">' ?>
<?php endif; ?>
<?php include_partial('common/flashes') ?>
<form id="doctor-health-advice-form" action="<?php echo url_for('@doctor_health_advice_new') ?>" method="post">
    <?php echo $form->renderHiddenFields(false) ?>
    <div class="imperative">What health advice do you have for the community?</div>
    <?php include_partial("common/input_field", array("form" => $form, "field" => "topic")) ?>
    <?php include_partial("common/input_field", array("form" => $form, "field" => "description")) ?>
    <div class="row">
        <ul>
            <li>
                <button id="submit-doctor-health-advice" type="submit" class="blue-button-30">Submit</button>
                <input id="done-doctor-health-advice" type="button" value="Done" class="brown-button-30">
            </li>
        </ul>
    </div>
    <div class="clear"></div>
</form>
<script type="text/javascript">
    //<![CDATA[
    $(document).ready(function(){
        // make an attempt to submit this form
        $('#submit-doctor-health-advice').click(function() {
            $('#doctor-health-advice-form').ajaxSubmit(function(data){
                if(hasForm(data))
                { 
                    $('#health-advice-form-holder').html(data);
                }
                else{ 
                    // automatically load the doctor health advice and a fresh form
                    $("#health-advice-form-holder").load('<?php echo url_for('@doctor_health_advice_new') ?>');
                    $.get('/doctor-health-advice/show/' + data, {}, function(adviceData){ 
                        $('#doctor-health-advices').prepend(adviceData);
                    }, 'html');
                }
            });
            return false;
        });
        
        $("#done-doctor-health-advice").click(function(){
            $.fn.colorbox.close();
        }); 
    });
    //]]>
</script>
<?php if (!$sf_request->isMethod('POST')): ?>
    <?php echo '</div>' ?>
<?php endif; ?>